﻿using System;
using HigLabo.Net.Extensions;

namespace HigLabo.Net.WindowsLive
{
    /// <summary>
    /// 
    /// </summary>
    public class LiveObject : ResponseObject
    {
        /// <summary>
        /// 
        /// </summary>
        public String ID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public IdName From { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Description { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ParentID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String UploadLocation { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Link { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Type { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public FileSharedWith SharedWith { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset? CreatedTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset? UpdatedTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public LiveObject(String jsonText)
        {
            this.SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public override void SetProperty(String jsonText)
        {
            var d = this.SetData(jsonText);
            this.ID = d.ToString("id");
            this.Name = d.ToString("name");
            if (d.ContainsKey("from") == true)
            {
                this.From = new IdName(d.ToString("from"));
            }
            this.Description = d.ToString("description");
            this.ParentID = d.ToString("parent_id");
            this.UploadLocation = d.ToString("upload_location");
            this.Link = d.ToString("link");
            this.Type = d.ToString("type");
            if (d.ContainsKey("shared_with") == true)
            {
                this.SharedWith = new FileSharedWith(d.ToString("shared_with"));
            }
            this.CreatedTime = d.ToDateTimeOffset("created_time");
            this.UpdatedTime = d.ToDateTimeOffset("updated_time");
        }
    }
}
